/*
 * libThreads.c
 *
 *  Created on: 25/03/2012
 *      Author: utnso
 */

#include "libThreads.h"

void apilarThread(t_nodoThread** pilaThreads, pthread_t tid){
	t_nodoThread* thread = (t_nodoThread*) malloc(sizeof(t_nodoThread));
	thread->tid = tid;
	(*thread).sig = *pilaThreads;
	*pilaThreads = thread;
}

void desapilarThread(t_nodoThread** pilaThreads, pthread_t* tid){
	*tid = (*pilaThreads)->tid;
	t_nodoThread* aux = (t_nodoThread*) malloc(sizeof(t_nodoThread));
	aux = (*pilaThreads);
	(*pilaThreads) = (*pilaThreads)->sig;
	free(aux);
}

void esperarThreads(t_nodoThread** pilaThreads){
	while((*pilaThreads) != NULL){
	pthread_t tid;
	desapilarThread(pilaThreads, &tid);
	pthread_join(tid, NULL);
	}
}
